//
//  ShortcutMethod.m
//  JQKit
//
//  Created by JQZ on 2017/11/22.
//  Copyright © 2017年 JQZ. All rights reserved.
//

#import "ShortcutMethod.h"
#import "ShortcutMacros.h"

UILabel *createLabel(UIFont *textFont, UIColor *textColor)
{
    UILabel *label = [[UILabel alloc] init];
    [label setFont:textFont];
    [label setTextColor:textColor];
    return label;
}

UIButton *createButton(UIFont *titleFont, UIColor *titleColor, id target, SEL touchUpInsideAction)
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    !titleFont ? : [button.titleLabel setFont:titleFont];
    !titleColor ? : [button setTitleColor:titleColor forState:UIControlStateNormal];
    if (target && touchUpInsideAction) {
        [button addTarget:target action:touchUpInsideAction forControlEvents:UIControlEventTouchUpInside];
    }
    return button;
}

UIEdgeInsets safeAreaInset(UIView *view)
{
    if (@available(iOS 11.0, *)) {
        return view.safeAreaInsets;
    }
    return UIEdgeInsetsZero;
}

UIEdgeInsets safeAreaInsetsForIPhoneX(void)
{
    if (!SCRREN_IPHONEX){
        return UIEdgeInsetsZero;
    }
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    switch (orientation) {
        case UIInterfaceOrientationPortrait:
            return UIEdgeInsetsMake(44, 0, 34, 0);
            
        case UIInterfaceOrientationPortraitUpsideDown:
            return UIEdgeInsetsMake(34, 0, 44, 0);
            
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            return UIEdgeInsetsMake(0, 44, 21, 44);
            
        case UIInterfaceOrientationUnknown:
        default:
            return UIEdgeInsetsMake(44, 0, 34, 0);
    }
}
